import { Texture2D } from "cc";
import { Conditional } from "./Utils/Decorator";

export class Utilities {


	/**
	 * 
	 * If the input is [a, b, c], the result will be [0, a, a+b, a+b+c]
	 * @param input int数组
	 * @returns 
	 */
	static cumSum(input: number[]): number[] {
		let runningSum = 0;
		const result = new Array(input.length + 1).fill(0);
		input.forEach((element, index) => {
			runningSum += element;
			result[index + 1] = runningSum;
		});

		return result;
	}

	@Conditional("CCC_DEV")
	static debugCheckNullAndNaN(value: number, valueCategory: string, caller: string) {
		if (value === null || isNaN(value) || value === undefined) {
			throw new Error(`Invalid ${valueCategory} value in ${caller}`);
		}
	}

	static destroyTexture(texture: Texture2D) {
		texture.destroy();
	}
}
